<template>

  <div>
    <div class="recharge-hd">
      <span>实名认证</span>
      <!-- <el-button size="mini" v-if="myInfo.isReal==2 && !dialogRealyVisible" :disabled="disabled" @click="realproves(true)" type="danger">修改信息</el-button> -->
      <!-- <el-button size="mini" v-if="myInfo.isReal==2 && dialogRealyVisible" :disabled="disabled" @click="realproves(false)" type="danger">取消修改</el-button> -->
    </div>
    <el-form v-if="myInfo.isReal==0 " :rules="rules" ref="ruleForm" :model="ruleForm" label-width="150px" v-loading='loading'>
      <div class="relboxmain">
        <div class="relbox">
          <el-form-item label="姓名：" prop="userName">
            <el-input v-model="ruleForm.userName" />
          </el-form-item>
          <el-form-item label="身份证号码：" prop="userCardNum">
            <el-input v-model="ruleForm.userCardNum" />
          </el-form-item>
          <el-form-item label="手机号码：" prop="mobile">
            <el-input v-model="ruleForm.mobile" />
          </el-form-item>
          <el-form-item label="手机验证：" prop="code">
            <el-input style="width:64%" v-model="ruleForm.code" />
            <div class="codephone" @click="getLoginCode" v-if='isCodeShow'>{{codespan}}</div>
            <div class="codephone del" v-if='!isCodeShow'>{{codespan}}</div>
          </el-form-item>
          <!-- <el-form-item label="提现密码：" prop="bankPass">
            <el-input v-model="ruleForm.bankPass" />
          </el-form-item> -->
        </div>

      </div>

      <el-form-item>
        <el-button style="width:150px" :loading='loading' @click="handlePublish" type="danger">保存</el-button>
        <!-- <el-button v-if="dialogRealyVisible" :loading='loading' @click="handleAmend" type="danger">确定修改</el-button> -->
      </el-form-item>
    </el-form>
    <div v-if="myInfo.isReal==1" class="myrealy">实名认证成功</div>
    <div v-if="myInfo.isReal==2" class="myrealy">审核未通过</div>
    <div v-if="myInfo.isReal==3" class="myrealy">资料以及提交审核中.....</div>
  </div>
</template>

<script>
export default {
  name: 'realName',
  data () {
    return {
      loading: false,
      isCodeShow: true,
      codespan: '获取验证码',
      rules: {
        userName: [
          {
            required: true,
            message: '请输入用户名'
          }
        ],
        userCardNum: [
          {
            required: true,
            message: '请输入身份证号码'
          },
          {
            validator: function (rule, value, callback) {
              var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/
              if (!reg.test(value)) {
                callback(new Error('身份证号码格式不正确'))
              } else {
                callback()
              }
            }
          }
        ],
        mobile: [
          {
            required: true,
            message: '请输入手机号'
          },
          {
            validator: function (rule, value, callback) {
              var reg = /^1[3|4|5|6|7|8|9]\d{9}$/
              if (!reg.test(value)) {
                callback(new Error('手机号码格式不正确'))
              } else {
                callback()
              }
            }
          }
        ],
        code: [
          {
            required: true,
            message: '请输入手机验证码'
          },
          {
            minLength: 4,
            message: '密码长度最少 4 个字符'
          }
        ]
      },

      ruleForm: {
        birthday: '',
        gender: '',
        userCardNum: '',
        userName: '',
        mobile: '',
        code: ''
      }
    }
  },
  props: ['myInfo'],
  computed: {},

  mounted () {
    this.init()
  },
  methods: {
    init () {},

    getLoginCode () {
      // 获取登录验证码

      this.$refs.ruleForm.validateField(['mobile'], valid => {
        if (!valid) {
          clearInterval(this.time)
          let numberTime = 60
          this.isCodeShow = false
          this.time = setInterval(() => {
            numberTime--
            if (numberTime <= 0) {
              numberTime = 60
              clearInterval(this.time)
              this.codespan = '获取验证码'
              this.isCodeShow = true
              return
            }
            this.codespan = numberTime + '秒后获取'
          }, 1000)

          this.$apis
            .currencyCaptcha({
              mobile: this.ruleForm.mobile
            })
            .then(res => {
              if (res.data.errno == 0) {
                this.$message.success('获取验证码成功')
              } else {
                this.$message.error(res.data.errmsg)
              }
            })
        }
      })
    },

    // handleAmend () {
    //   // 修改实名
    //   this.$refs['ruleForm'].validate(valid => {
    //     if (valid) {
    //       this.loading = true
    //       this.$apis.realUpdate(this.ruleForm).then(res => {
    //         if (res.data.errno == 0) {
    //           this.$notify.success({
    //             title: '成功',
    //             message: '修改实名认证成功'
    //           })
    //           location.reload()
    //           // this.getInfo()
    //         } else {
    //           this.$notify.error({
    //             title: '错误',
    //             message: res.data.errmsg
    //           })
    //         }
    //         this.loading = false
    //       })
    //     } else {
    //       this.$message({
    //         message: '请检查数据必填项',
    //         type: 'warning'
    //       })
    //       return false
    //     }
    //   })
    // },
    handlePublish () {
      // 增加实名
      this.$refs['ruleForm'].validate(async valid => {
        if (valid) {
          this.loading = true
          var data = await this.$apis
            .currencyCheckCaptcha({
              mobile: this.ruleForm.mobile,
              code: this.ruleForm.code
            })
            .then(res => {
              return res
            })
          if (data.data.errno == 0) {
            this.$apis.realCreate(this.ruleForm).then(res => {
              if (res.data.errno == 0) {
                this.$notify.success({
                  title: '成功',
                  message: '实名认证成功'
                })
                this.$parent.getInfo()
              } else {
                this.$notify.error({
                  title: '错误',
                  message: res.data.errmsg
                })
              }
              this.loading = false
            })
          } else {
            this.$message({
              message: data.data.errmsg,
              type: 'error'
            })
            this.loading = false
          }
        } else {
          this.$message({
            message: '请检查数据必填项',
            type: 'warning'
          })
          return false
        }
      })
    },
    bindProvince (e) {
      this.ruleForm.bankCity = ''
      this.cityListOld.map(item => {
        if (item.code == e) {
          this.cityList = item.children
          this.ruleForm.bankProvince = item.name
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
.con-t-select {
  margin-top: 0px;
}
.content {
  display: flex;
  min-height: 100vh;
}
.myorderform {
  flex: 1;
  background-color: #fafafa;
}
.myset {
  text-align: center;
  padding: 70px 20px 50px;
  font-size: 16px;
  img {
    width: 90px;
    height: 90px;
    border-radius: 50%;
    margin-bottom: 10px;
  }
  div {
    span {
      color: #d1483f;
    }
  }
}
.myorderform-title {
  font-size: 18px;
  margin-bottom: 30px;
  text-align: center;
}
.goodsbuy {
  padding: 15px 0px;
  color: #828282;
  font-size: 18px;
  cursor: pointer;
  text-align: center;
}
.goodsbuyatv {
  border-left: 4px solid #d82141;
  background-color: #fff;
}
.orderform {
  background-color: #fff;
  padding: 60px 40px;
  flex: 4;
  box-sizing: border-box;
}
.allorders {
  display: flex;
  margin-bottom: 20px;
}
.cancellation-order {
  border-right: 2px solid #ddd;
  padding: 0px 30px;
  cursor: pointer;
  font-size: 16px;
  font-weight: bold;
}
.cancellation-active {
  color: #d82141;
}
.cancellation-order:last-child {
  border: none;
}
.cancellation-order:first-child {
  padding-left: 0;
}
.uni-input {
  border: 1px solid #e4e4e4;
  width: 30%;
  border-radius: 10px;
  padding: 10px 0;
  padding-left: 20px;
  margin-bottom: 40px;
}
.indent-select {
  display: flex;
  .uni-data-select {
    margin-right: 10px;
  }
  img {
    width: 80px;
    height: 60px;
  }
}
.uni-stat__select {
  margin-right: 40px;
  margin-bottom: 40px;
}
.seedetails {
  color: #fff;
  background: linear-gradient(#d82141, #f36638);
}

.recharge-hd {
  border-left: 3px solid #d82141;
  padding: 2px 10px;
  margin-bottom: 30px;
}
.recharge-bd {
  width: 500px;
  margin-left: 150px;
}

.recharg-but {
  margin-left: 100px;
  margin-top: 20px;
}

.particulars {
  margin: 30px 0px;
  padding: 15px;
  border-top: 1px solid #efefef;
  border-bottom: 1px solid #efefef;
}
.particulars-item {
  display: flex;
  line-height: 30px;
  b {
    color: #444444;
    font-size: 14px;
    flex: 1;
  }
  span {
    color: #888888;
    font-size: 16px;
    flex: 3;
  }
}

.myInfo {
  margin-top: 10px;
  .icon {
    font-style: normal;
    color: #986e32;
    font-size: 12px;
    background: #ffe863;
    border: 1px #986e32 dashed;
    padding: 2px 3px;
    vertical-align: middle;
    cursor: pointer;
    white-space: nowrap;
  }
}
.relbox {
  width: 600px;
}
</style>